<?php
/**
* kiem tra session
*/

class AuthModel {
	/**
	* Luu gia tri vao session
	*/
	function setIdentity($username) {
		$session = new Zend_Session_Namespace();
		Zend_Loader::loadClass('UserModel');
		$model = new UserModel();
		$user_info = $model->getUserInfoByName($username);
		$identity_arr = array(
			'username' => $username,
			'id'  => $user_info['id'],
			'powers' => $user_info['quyenHan'],
			'email' => $user_info['Email'] 
		);

		$session->identity = $identity_arr;
	}

	/**
	* Kiem tra da co session chua
	*/
	function hasIdentity() {
		$session = new Zend_Session_Namespace();
		return $session->identity ? true : false;
	}

	/**
	* Lay thong tin session
	*/
	function getIdentity() {
		$session = new Zend_Session_Namespace();
		return $session->identity;
	}
	function getIdentityField() {
		if ($this->hasIdentity()) {
			$identity = $this->getIdentity();
			return $identity['username'];
		}
		else
			return NULL;
	}

	/**
	* Xoa thong tin o session
	*/
	function clearIdentity() {
		$session = new Zend_Session_Namespace();
		unset($session->identity);
	}
}
?>